package com.lex.newbasketball.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2016/7/12.
 */
public abstract class BaseFragment extends Fragment {
    private View layouView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (layouView==null) throw new NullPointerException("请在onGreate方法中调用setContentView设置fragment布局");
        else return layouView;
    }
    public void setContentView(View layouView){
        this.layouView=layouView;
    }
    public void setContentView(int layoutId){
        layouView=View.inflate(getActivity(),layoutId,null);
    }
    public View findViewById(int resId){
        if (layouView==null)throw new NullPointerException("必须在onCreateView之后调用finViewById");
        else return layouView.findViewById(resId);
    }
    public View getRootView(){
        return layouView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        findView();
        initView();
    }

    protected abstract void findView();
    protected abstract void initView();
}
